/**
 * Project Name:spring-config-client File Name:EndpointAutoConfiguration.java Package
 * Name:org.spring.config.client.controller Date:2019年10月16日下午7:50:38 Copyright (c) 2019, dengqian37@126.com All Rights
 * Reserved.
 *
 */

package org.spring.cloud.pilot.configuration;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spring.cloud.pilot.endpoint.DownEndpoint;
import org.spring.cloud.pilot.endpoint.RebootEndpoint;
import org.spring.cloud.pilot.endpoint.StopEndpoint;
import org.spring.cloud.pilot.endpoint.UpEndpoint;
import org.spring.cloud.pilot.endpoint.mvc.DownMvcEndpoint;
import org.spring.cloud.pilot.endpoint.mvc.RebootMvcEndpoint;
import org.spring.cloud.pilot.endpoint.mvc.StopMvcEndpoint;
import org.spring.cloud.pilot.endpoint.mvc.UpMvcEndpoint;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * ClassName:EndpointAutoConfiguration <br/>
 * Function: TODO ADD FUNCTION. <br/>
 * Reason: TODO ADD REASON. <br/>
 * Date: 2019年10月16日 下午7:50:38 <br/>
 * 
 * @author dengqian
 * @version
 * @since JDK 1.8
 * @see
 */
@Configuration
@ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled")
public class EndpointAutoConfiguration {
    private static final Logger LOGGER = LoggerFactory.getLogger(EndpointAutoConfiguration.class);

    @Bean
    public StopEndpoint stopEndpoint() {
        StopEndpoint endpoint = new StopEndpoint("stop");
        return endpoint;
    }

    @Bean
    @ConditionalOnBean(StopEndpoint.class)
    public StopMvcEndpoint stopMvcEndpoint(StopEndpoint stopEndpoint) {
        StopMvcEndpoint stopMvcEndpoint = new StopMvcEndpoint(stopEndpoint);
        return stopMvcEndpoint;
    }

    @Bean
    public DownEndpoint downEndpoint() {
        DownEndpoint endpoint = new DownEndpoint("down");
        return endpoint;
    }

    @Bean
    @ConditionalOnBean(DownEndpoint.class)
    public DownMvcEndpoint downpMvcEndpoint(DownEndpoint downEndpoint) {
        DownMvcEndpoint downMvcEndpoint = new DownMvcEndpoint(downEndpoint);
        return downMvcEndpoint;
    }

    @Bean
    public UpEndpoint upEndpoint() {
        UpEndpoint endpoint = new UpEndpoint("up");
        return endpoint;
    }

    @Bean
    @ConditionalOnBean(UpEndpoint.class)
    public UpMvcEndpoint upMvcEndpoint(UpEndpoint upEndpoint) {
        UpMvcEndpoint downMvcEndpoint = new UpMvcEndpoint(upEndpoint);
        return downMvcEndpoint;
    }

    @Bean
    public RebootEndpoint rebootEndpoint() {
        RebootEndpoint endpoint = new RebootEndpoint("reboot");
        return endpoint;
    }

    @Bean
    @ConditionalOnBean(RebootEndpoint.class)
    public RebootMvcEndpoint rebootMvcEndpoint(RebootEndpoint rebootEndpoint) {
        RebootMvcEndpoint endpoint = new RebootMvcEndpoint(rebootEndpoint);
        return endpoint;
    }


}
